package com.huawei.weather.controller;

import com.huawei.weather.domain.WeatherDayData;
import com.huawei.weather.domain.WeatherResponse;
import com.huawei.weather.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class WeatherController2 {


    @Autowired
    WeatherService weatherService;

    @RequestMapping("/find2")
    public ModelAndView find2(@RequestParam(value="cityId",defaultValue = "101030100") String cityId){

       //1.获取查询结果   2.实例化ModelAndView对象   3.跳转到目标页面
        WeatherResponse weatherResponse=weatherService.findWeatherByCityId(cityId);

        for(WeatherDayData wd:weatherResponse.getResult().getList()){
            wd.setWeatherimg("images/"+wd.getWeatherimg());
        }


        ModelAndView mav=new ModelAndView();
        mav.addObject("weatherData",weatherResponse);
        mav.setViewName("weather");  //  emp.html  视图解析器： classpath:/templates/前缀+emp+后缀.html

        return mav;


    }
}
